package com.zj.core.base

import android.annotation.SuppressLint
import android.app.Application
import android.content.*
import android.net.ConnectivityManager
import android.os.IBinder
import com.customcamera.CustomCameraAgent.*
import com.moduleinterface.InterfaceInitApp
import com.zj.datacoll.BleToothManager
import com.zj.core.services.BleToothService
import com.zj.core.services.NetBroadReceiver
import android.content.Intent


class BaseApplication :Application(){
    override fun onCreate(){
        super.onCreate()

        context =this

        /**
         * 相机
         */
        init(this)
        openLog()

        /**
         * Bmob
         */
        //initialize(app, "0422d92674a4f5dcfbfa199f55672bda")

//        /**
//         * 极光推送
//         */
//        JPushInterface.setDebugMode(true)  //正式版的时候设置false，关闭调试
//        JPushInterface.init(this)

//        /**
//         * bugly
//         */
//        CrashReport.initCrashReport(this, "5f8cc5510b", true)

        /**
         * 网络状态
         */
        IntentFilter().apply {
            addAction(ConnectivityManager.CONNECTIVITY_ACTION)
            registerReceiver(NetBroadReceiver(),this)
        }

        /**
         * 蓝牙连接
         */
        Intent(this, BleToothService::class.java).apply {
            bindService(this,BleServiceCon(),Context.BIND_AUTO_CREATE)
        }
    }

	class BleServiceCon: ServiceConnection {
        override fun onServiceDisconnected(name: ComponentName?) {
            mBleToothBind =null
        }
        override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
            mBleToothBind = BleToothManager.Stub.asInterface(service)
        }
    }

    companion object {
        @SuppressLint("StaticFieldLeak")
        var context:Context?=null
        var mBleToothBind:BleToothManager?=null
    }
}